import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

//无返回值无参数
@FunctionalInterface
interface NoParameterNoReturn {
    void test();
}
//无返回值一个参数
@FunctionalInterface
interface OneParameterNoReturn {
    void test(int a);
}

//无返回值多个参数
@FunctionalInterface
interface MoreParameterNoReturn {
    void test(int a,int b);
}
//有返回值无参数
@FunctionalInterface
interface NoParameterReturn {
    int test();
}

//有返回值一个参数
@FunctionalInterface
interface OneParameterReturn {
    int test(int a);
}
//有返回值多参数
@FunctionalInterface
interface MoreParameterReturn {
    int test(int a,int b);
}


public class lambdademo {
    public static void main(String[] args){
        HashMap<String,Integer> map=new HashMap<>();
        map.put("hello",1);
        map.put("end",2);
        map.put("abc",3);
        map.forEach((key,val)->System.out.println("key"+":"+key+"  "+"value"+":"+val));
    }
    public static void main7(String[] args){
        ArrayList<String> List=new ArrayList<>();
        List.add("abcd");
        List.add("def");
        List.add("cde");
        List.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        System.out.println("============");
        List.forEach(s->System.out.println(s));

    }
    public static void main6(String[] args){
        MoreParameterReturn moreParameterReturn=
                (a, b) ->a*b;
        System.out.println(moreParameterReturn.test(20,3));
    }
    public static void main5(String[] args){
        OneParameterReturn oneParameterReturn=
                a -> a+3;
        System.out.println(oneParameterReturn.test(1));
    }
    public static void main4(String[] args){
        NoParameterReturn noParameterReturn=
                ()->10;
       System.out.println( noParameterReturn.test());

    }
    public static void main3(String[] args){
        MoreParameterNoReturn moreParameterNoReturn=
                (a,b)->System.out.println(a+b);
        moreParameterNoReturn.test(10,20);
    }
    public static void main2(String[] args){
        OneParameterNoReturn oneParameterNoReturn=
                a -> System.out.println("有一个参数无返回值");
        oneParameterNoReturn.test(10);
    }
    public static void main1(String[] args){
        NoParameterNoReturn noParameterNoReturn=new NoParameterNoReturn() {
            @Override
            public void test() {
                System.out.println("无参数无返回值");
            }
        };
        noParameterNoReturn.test();
        System.out.println("==============");
        NoParameterNoReturn noParameterNoReturn1=
                ()->System.out.println("无参数无返回值");
        noParameterNoReturn1.test();
    }

}
